package cn.edu.seu.java.parser;

import java.util.List;

import org.eclipse.jdt.core.dom.CompilationUnit;

import cn.edu.seu.io.util.IO;

public class TestMain {
	public static void main(String[] args) {
		IO.clear(); // Attention...

		String versionPath = "F:/SmellWorkspace/ChangeDetector5.1";
		//versionPath = "F:/SmellWorkspace/refactoring0.1";
		versionPath = "F:/corpus/kafka/kafka#2017-06-23-07-45-47#0.11.0.0#e18335d";
		//versionPath = "F:/corpus/camel/camel#2017-04-30-04-44-54#camel-2.19.0#6cb0023";
		//List<String> projPaths = Arrays.asList("F:/corpus/kafka/kafka#2017-06-23-07-45-47#0.11.0.0#e18335d");

		BatchedASTParser astParser = new BatchedASTParser(versionPath);
		List<CompilationUnit> units = astParser.generateCompilationUnits();

		for (CompilationUnit unit : units) {
			String sourceFilePath = (String) unit.getProperty("sourceFilePath");

			/*unit.accept(new ASTVisitor() {
				@Override
				public boolean visit(TypeDeclaration node) {
					System.out.println(node.getName().getIdentifier());
					System.out.println(node.getName().getFullyQualifiedName());
					System.out.println();
					
					return true;
				}
				
				@Override
				public boolean visit(MethodInvocation node) {
					IMethodBinding callee = node.resolveMethodBinding();
					if (callee != null) {
						ITypeBinding iTypeBinding = callee.getDeclaringClass();
						if (iTypeBinding.isParameterizedType() && iTypeBinding.isFromSource()) {
							IOUtil.outputToFile(sourceFilePath);
							IOUtil.outputToFile(ASTNodeUtil.getStartLine(node));
							
							IOUtil.outputToFile(iTypeBinding.getBinaryName());
							IOUtil.outputToFile(StringUtil.convert(iTypeBinding.getBinaryName()));
							
							//IOUtil.outputToFile(iTypeBinding.getKey());
							//IOUtil.outputToFile(StringUtil.convert(iTypeBinding.getKey()));
							
							IOUtil.outputToFile("");
						}
					}
					return true;
				}
			
				@Override
				public boolean visit(MethodDeclaration node) {
					IMethodBinding callee = node.resolveBinding();
					if (callee != null) {
						ITypeBinding iTypeBinding = callee.getDeclaringClass();
						if (iTypeBinding.isParameterizedType() && iTypeBinding.isFromSource()) {
							IOUtil.outputToFile(sourceFilePath);
							IOUtil.outputToFile(ASTNodeUtil.getStartLine(node));
							
							IOUtil.outputToFile(iTypeBinding.getBinaryName());
							IOUtil.outputToFile(StringUtil.convert(iTypeBinding.getBinaryName()));
							
							//IOUtil.outputToFile(iTypeBinding.getKey());
							//IOUtil.outputToFile(StringUtil.convert(iTypeBinding.getKey()));
							
							IOUtil.outputToFile("");
						}
					}
					return true;
				}
			});*/
		}

		System.out.println(units.size());

	}
}
